package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: StudentController
 * @Author: HH
 * @Date: 2025/4/19 18:04
 **/

/**
 * 学员管理Controller
 */
@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 条件分页查询学生信息
     */
    @GetMapping
    public Result page(StudentQueryParam param) {
        log.info("请求参数： {}", param);
        PageBean pageBean = studentService.page(param);
        return Result.success(pageBean);
    }

    /**
     * 添加学生
     */
    @PostMapping
    public Result insert(@RequestBody Student student) {
        log.info("添加学生: {}", student);
        studentService.insert(student);
        return Result.success();
    }

    /**
     * 根据id查询学生
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("根据id查询学生: {}", id);
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    /**
     * 修改学员信息
     */
    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("修改学员信息: {}", student);
        studentService.update(student);
        return Result.success();
    }

    /**
     * 批量删除学生
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("批量删除学生: {}", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result handle(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("违纪处理: {}, {}", id, score);
        studentService.handle(id, score);
        return Result.success();
    }
}
